﻿CREATE PROCEDURE [dbo].[Environment_InsertUpdate]

	@id					BIGINT,

	@name				VARCHAR (0060), 

	@description		VARCHAR (0999),


	@databaseType		INT, 

	@serverName			VARCHAR (0060),

	@databaseName		VARCHAR (0060),

	@poolingEnabled		BIT,

	@poolSizeMinimum	INT,

	@poolSizeMaximum	INT,

	@trustedConnection	BIT,

	@userName			VARCHAR (0060),

	@password			VARCHAR (0060),

	@customAttributes	VARCHAR (0060),


	@modifiedId					VARCHAR (0060)


	
AS

	BEGIN 

		MERGE Environment

			USING (SELECT @id) AS Source (Id)

				ON Environment.Id = Source.Id

			WHEN MATCHED THEN 

				UPDATE SET 

					Name = @name,

					Description = @description,

					DatabaseType = @databaseType,

					ServerName = @serverName, 

					DatabaseName = @databaseName,

					PoolingEnabled = @poolingEnabled,

					PoolSizeMinimum = @poolSizeMinimum,

					PoolSizeMaximum = @poolSizeMaximum, 

					TrustedConnection = @trustedConnection,

					UserName = @userName,

					Password = @password,

					CustomAttributes = @customAttributes,

					ModifiedId = @modifiedId,

					ModifiedDateTime = GETDATE ()

			WHEN NOT MATCHED THEN 

				INSERT (Name, Description, DatabaseType, ServerName, DatabaseName, PoolingEnabled, PoolSizeMinimum, PoolSizeMaximum, TrustedConnection, UserName, Password, CustomAttributes, CreateId, CreateDateTime, ModifiedId, ModifiedDateTime) 

					VALUES (@name, @description, @databaseType, @serverName, @databaseName, @poolingEnabled, @poolSizeMinimum, @poolSizeMaximum, @trustedConnection, @userName, @password, @customAttributes, @modifiedId, GETDATE (), @modifiedId, GETDATE())

		; -- MERGE ( END )


	END

	